<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改文件信息配置')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-fileconf-edit" th:object="${fileConf}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">业务类型：</label>
            <div class="col-sm-8">
                <input name="bizeType" th:field="*{bizeType}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文件类型：</label>
            <div class="col-sm-8">
                <select name="fileTypeLimit" id = "fileTypeLimit" class="form-control noselect2 selectpicker"
                        data-none-selected-text="请选择文件类型" multiple th:with="type=${@dict.getType('file_type')}">
                    <option th:each="dict:${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${#strings.contains(fileConf.fileTypeLimit,dict.dictValue)}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文件大小(kb)：</label>
            <div class="col-sm-8">
                <input name="fileSizeLimit" th:field="*{fileSizeLimit}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">存储文件夹名称：</label>
            <div class="col-sm-8">
                <input name="path" th:field="*{path}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <input name="description" th:field="*{description}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否可用：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="status" th:checked="${fileConf.enabled == '1' ? true : false}">
                    <span></span>
                </label>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script type="text/javascript">
    var prefix = ctx + "file/fileconf";
    $("#form-fileconf-edit").validate({
        rules:{
            fileSizeLimit:{
                number:true,
                min:0
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-fileconf-edit").serializeArray();
            var enabled = $("input[id='status']").is(':checked') == true ? 1 : 0;
            var fileTypeLimit = $("select[id='fileTypeLimit']").val();
            if(fileTypeLimit==null){
                data.push({"name": "fileTypeLimit", "value": ""});
            }
            var fileTypeLimit = $("input[id='fileSizeLimit']").val();
            data.push({"name": "enabled", "value": enabled});
            $.operate.save(prefix + "/edit", data);
        }
    }

</script>
</body>
</html>